package com.zhoukx.dependencyinversion;

/**
 * @ClassName ICar
 * @Description:
 * @Author zhoukx
 * @Date 2020/8/4
 **/
public class MainCar {

    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        Behavior behavior = new Behavior();
        behavior.setIcar(Bus.class);
       // behavior.getiCar().getName("公共汽车");
    }

}

interface  ICar{

    String getName(String name);
}

class  Bus implements  ICar{

    @Override
    public String getName(String name) {
        return name;
    }
}

class Car implements  ICar{

    @Override
    public String getName(String name) {
        return name;
    }
}

class  Behavior {
    private  ICar iCar;

    public Behavior() {
    }

    public Behavior(ICar iCar) {
        this.iCar = iCar;
    }

    public void setIcar(Class  t) throws IllegalAccessException, InstantiationException {
        ICar o = (ICar) t.newInstance();
        System.out.println(  o.getName("公共汽车"));
    }

    public ICar getiCar() {
        return iCar;
    }

    public void setiCar(ICar iCar) {
        this.iCar = iCar;
    }
}
